package com.zg.api.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.api.domain.convert.ApiCategoryConvert;
import com.zg.api.domain.req.ApiCategoryAddReq;
import com.zg.api.domain.req.ApiCategoryEditReq;
import com.zg.api.domain.req.ApiCategoryPageReq;
import com.zg.api.domain.vo.ApiCategoryVo;
import com.zg.api.service.ApiCategoryService;
import com.zg.common.core.R;
import com.zg.common.core.dao.apis.entity.ApiCategory;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/16 20:23
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/category")
@Slf4j
@Api(tags = "接口分类")
public class ApiCategoryController {


    private final ApiCategoryService apiCategoryService;

    private final ApiCategoryConvert categoryConvert;

    @PostMapping("/page")
    public R page(@RequestBody ApiCategoryPageReq pageReq) {
        Page<ApiCategoryVo> page = apiCategoryService.page(pageReq, ApiCategoryVo.class);
        return R.success(page);
    }


    @PostMapping("/add")
    public R add(@Validated @RequestBody ApiCategoryAddReq addReq) {
        apiCategoryService.add(addReq);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@Validated @RequestBody ApiCategoryEditReq editReq) {
        apiCategoryService.edit(editReq);
        return R.success();
    }

    @PostMapping("/remove")
    public R remove(@RequestBody  List<Long> ids) {
        apiCategoryService.remove(ids);
        return R.success();
    }

    @GetMapping("/list")
    public R<List<ApiCategoryVo>> list() {
        List<ApiCategory> vList=apiCategoryService.list();
        return R.success(categoryConvert.toVoList(vList));
    }
}
